************************************************************************************************************************  
* Touching Beliefs: Using Touchscreen Technology to Elicit Beliefs and Subjective Expectations in Survey Research
************************************************************************************************************************  
* Author: Elisa M. Maffioli
* This dofile reproduce all tables and figures in the article

use "data_slidervalidation.dta", clear
set scheme sol

*---------------------------------------------------------------------------------
* Table 1 - Descriptive statistics and balance check
*---------------------------------------------------------------------------------

* column 1 - sample mean
sum female age married hindu lowcaste low_up_primary occ_agric house_own wealth_index income_30d food_exp_30d

* comparison between beans and slider
do "${dofiles}/code for ttest, v2.do"
eststo clear
	eststo: randomization_table female age married hindu lowcaste low_up_primary occ_agric ///
	house_own wealth_index income_30d food_exp_30d, tmtvar(treatment) groups(1 2) 
	#delimit ;
	esttab using "table1.tex", 
				    cells("mean1(fmt(2)) mean2(fmt(2)) p_1V2_mod1(star pvalue(p_1V2_mod1) fmt(3))  n1(fmt(0)) & n2(fmt(0))" "sd1(par) sd2(par)") 
					starlevels(* .10 ** .05 *** .01) incelldelimiter(" / ")
					coll("Beans" "Slider" "Pvalue"  "N(Beans/Slider)")
					addnote("Means - Standard Deviations in Parenthesis." 
					"\sym{*} \(p<.10\), \sym{**} \(p<.05\), \sym{***} \(p<.01\)") 
					nonumber noobs nomtitles label replace booktabs ;			
	#delimit cr

	
*---------------------------------------------------------------------------------
* Table 2 - Descriptive statistics, subjective expectations
*---------------------------------------------------------------------------------

estimates clear
estpost summarize ball_s student_girl_s river_dryup_s diwali_holiday_s market_2d_s market_2w_s prob_beingalive_10y_s prob_beingalive_20y_s age_tolive ///
prob_beingalive_10y_diabetes_s prob_beingalive_20y_diabetes_s age_tolive_diabetes ///
prob_beingalive_10y_nodiabetes_s prob_beingalive_20y_nodiabetes_s age_tolive_nodiabetes  /// 
inconsistent_0 inconsistent_100 inconsistent_market inconsistent_lifeexp10 inconsistent_lifeexp20  
esttab using "table2.tex", cells("mean(fmt(2)) sd(fmt(2))  min  max count(fmt(0))") noobs nomtitle nonumber label  replace


*---------------------------------------------------------------------------------
* Table 3 - Opinion on the elicitation method used and respondent’s involvement in the survey
*---------------------------------------------------------------------------------
	
do "${dofiles}/code for ttest, v2.do"
eststo clear
	eststo: randomization_table method_difficulty method_refusal accuracy attentiveness, tmtvar(treatment) groups(1 2) 
#delimit ;
	esttab using "table3.tex", 
				    cells("mean1(fmt(2)) mean2(fmt(2)) p_1V2_mod1(star pvalue(p_1V2_mod1) fmt(3))  n1(fmt(0)) & n2(fmt(0))" "sd1(par) sd2(par)") 
					starlevels(* .10 ** .05 *** .01) incelldelimiter(" / ")
					coll("Beans" "Slider" "Pvalue"  "N(Beans/Slider)")
					addnote("Means - Standard Deviations in Parenthesis." 
					"\sym{*} \(p<.10\), \sym{**} \(p<.05\), \sym{***} \(p<.01\)") 
					nonumber noobs nomtitles label replace booktabs ;			
	#delimit cr

	
*---------------------------------------------------------------------------------
* Time survey 
*---------------------------------------------------------------------------------	
ttest time_set_allsurvey, by(treatment) 



*---------------------------------------------------------------------------------
* Table 4 - Comparison of distributions of probability of having diabetes and being alive in 20 years (beans vs slider)
*---------------------------------------------------------------------------------
// The code generates inputs of the table, which was constructed manually in Latex

* Moments & Tests

foreach var of varlist likelihood_diabetes_s prob_beingalive_20y_s  {

* Generate moments
estpost tabstat `var', by(treatment) stats(n mean sd p5 p25 p50 p75 p95) nototal
esttab using "slider_moments_`var'.tex", cells("mean(fmt(2)) sd(fmt(2)) p5(fmt(2)) p25(fmt(2)) p50(fmt(2)) p75(fmt(2)) p95(fmt(2))  count(fmt(0))") ///
noobs nomtitle nonumber label replace

* Generate pvalues - tests
estimates clear

regress `var' treatment
ttest `var', by(treatment)	
outreg2 using "pvalues_`var'.tex", tex(frag) replace addstat(P-Value, `r(p)') nocons noobs drop(treatment)  nor2 ///
ctitle(Ttest Mean) nonotes

sdtest `var', by(treatment)
outreg2 using "pvalues_`var'.tex", tex(frag) append addstat(P-Value, `r(p)') nocons  noobs  drop(treatment)  nor2 ///
ctitle(Ttest Sd) nonotes 

ksmirnov `var', by(treatment)
outreg2 using "pvalues_`var'.tex", tex(frag) append addstat(P-Value, `r(p_cor)') nocons  noobs  drop(treatment)  nor2 /// 
ctitle(Test KS) nonotes 

ranksum `var', by(treatment)
estadd scalar pz=2 * normprob(-abs(r(z)))
outreg2 using "pvalues_`var'.tex", tex(frag) append addstat(P-Value, `e(pz)') nocons noobs  ///
drop(treatment) nor2 ctitle(Test MW) 

}


*---------------------------------------------------------------------------------
* Fig 2 - Focal Points
*---------------------------------------------------------------------------------

graph bar f0_2_5pc_likelihood_diabetes_s f50_2_5pc_likelihood_diabetes_s f100_2_5pc_likelihood_diabetes_s, over(treatment) ///
legend(label(1 "Focal Point 0%") label(2 "Focal Point 50%") label(3 "Focal Point 100%")) ///
ytitle("A. Probability of having diabetes") title("A. Probability of having diabetes") name(graph_likelihood_diabetes_s, replace)  

graph bar f0_2_5pc_prob_beingalive_20y_s f50_2_5pc_prob_beingalive_20y_s f100_2_5pc_prob_beingalive_20y_s, over(treatment) ///
legend(label(1 "Focal Point 0%") label(2 "Focal Point 50%") label(3 "Focal Point 100%")) ///
ytitle("B. Probability of being alive in 20 years") name(graph_beingalive_20y_s, replace) 

grc1leg graph_likelihood_diabetes_s graph_beingalive_20y_s, cols(1) iscale(*#1) graphregion(margin(zero)) ycommon xcommon 
graph export "graph_focalpoints.png", replace 


*** T-Test
foreach var of varlist  likelihood_diabetes_s prob_beingalive_20y_s  {
ttest f0_2_5pc_`var', by(treatment)
ttest f50_2_5pc_`var', by(treatment)
ttest f100_2_5pc_`var', by(treatment)
}

*---------------------------------------------------------------------------------
* Fig 3. Distribution of probability of having diabetes (beans vs slider).
*---------------------------------------------------------------------------------
label var likelihood_diabetes_s " "
label var prob_beingalive_20y_s " "

twoway (histogram likelihood_diabetes_s if treatment==1, start(0) color(gs10) frequency) ///
       (histogram likelihood_diabetes_s if treatment==2, start(0) frequency fcolor(none) lcolor(black)),legend(order(1 "Beans" 2 "Slider")) ///
name(graph_distr_diabetes_s,replace) 

twoway (histogram prob_beingalive_20y_s if treatment==1, start(0) color(gs10) frequency) ///
       (histogram prob_beingalive_20y_s if treatment==2, start(0) frequency fcolor(none) lcolor(black)),legend(order(1 "Beans" 2 "Slider")) ///
name(graph_distr_beingalive_20y_s,replace) 

grc1leg graph_distr_diabetes_s graph_distr_beingalive_20y_s,  cols(1) iscale(*#1) graphregion(margin(zero)) ///
ycommon xcommon
graph export "graph_distributions.png", replace 


*---------------------------------------------------------------------------------
* SUPPLEMENTARY INFORMATION - S1 Table A 
*---------------------------------------------------------------------------------
estpost summarize electricity television refrigerator mobilephone motorcycle bankaccount ///
material_wall_impr material_floor_impr material_roof_impr
esttab using "dhs_index.tex", cells("mean(fmt(a3)) sd(fmt(a3))  min  max count") noobs nomtitle nonumber ///
label title("Variables for PCA - Wealth Index") ///
addnotes("") replace






